<?php
class XA_Table_Field_Options extends XA_Table_Field {

	public $listview;



	public function __construct ($name, $label, $listview) {
		parent::__construct($name, $label);
		$this->listview = $listview;
	}



	public function out ($row) {
		$option_list = array();

		foreach ($this->listview->option_list as $option) {
			if (is_string($option['param_list'])) {
				parse_str($option['param_list'], $param_list);
			} else {
				$param_list = $option['param_list'];
			}

			foreach ($this->listview->pk_list as $pk) {
				$param_list[$pk] = $row[$pk];
			}
			
			foreach ($param_list as $key => $val) {
				if (
					$val === true
					&&
					isset($row[$key])
				) {
					$param_list[$key] = $row[$key];
				}
			}

			$option_list[] = '<a class="button '.$option['class'].'" href="'.xa::url($param_list).'" title="'.$option['label'].'"> </a>';
		}

		return '<td class="'.implode(' ', $this->class_list).'">'.implode(' ', $option_list).'</td>';
	}
}
